package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import com.sun.org.glassfish.gmbal.ParameterNames;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class Controller {

    @Autowired
    private UserService userService;

    @Value("${server.port}")
    private Integer port;

    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") String username, HttpServletRequest request) {

        String name = request.getHeader("name");
        String name1 = request.getHeader("name");
        System.out.println("name1 = " + name1);
        System.out.println("======================="+name);


        System.out.println(port);

        if (username.equals("itheima")) {
            throw new RuntimeException("ssssss");
        }
        return userService.findById(username);
    }
}
